package itstudio.instructor.adapter;

import itstudio.app.wq.R;
import itstudio.instructor.entity.News;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class MyPostAdapter extends BaseAdapter{
	private Context context;
	private LayoutInflater mInflater;
	DisplayImageOptions options;
	private ImageLoader imageLoader = ImageLoader.getInstance();
	private List<News> newsList;
	private News news ;

	public MyPostAdapter(Context context, List<News> newsList,DisplayImageOptions options) {
		this.newsList = newsList;
		this.context = context;
		this.mInflater = LayoutInflater.from(context);
		this.options = options;
		
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return newsList.size() ;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final PicModelHodler holder ;
		news = newsList.get(position);
		
		if(convertView == null){
			holder = new PicModelHodler();
			convertView = mInflater.inflate(R.layout.listitem_my_post, null);
			holder.txt_title = (TextView) convertView.findViewById(R.id.my_post_list_item_title);
			holder.txt_short_content = (TextView) convertView.findViewById(R.id.my_post_list_item_content);
			holder.txt_date = (TextView) convertView.findViewById(R.id.my_post_list_item_time);
		}
		else{
			holder = (PicModelHodler) convertView.getTag();
		}
		
		holder.txt_title.setText(news.getTitle());
		holder.txt_short_content.setText(news.getContent());
		holder.txt_date.setText(news.getDate());
		//给ImageView设置路径Tag,这是异步加载图片的小技巧
		convertView.setTag(holder);
		return convertView;
	}

	private final class PicModelHodler {
		public TextView txt_title;
		public TextView txt_date;
		public TextView txt_short_content;
	}
}
